
package com.hlkj.pay.gateway.order.impl;
/*
 * Hlpay-Plus aggregate payment system.
 * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
 */

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Service;

import com.hlkj.framework.common.pojo.CommonResult;
import com.hlkj.framework.extension.executor.ExtensionExecutor;
import com.hlkj.framework.extension.scenario.BizScenario;
import com.hlkj.pay.app.merchant.ext.ChannelMerchantRiskExtPt;
import com.hlkj.pay.app.merchant.ext.dto.order.ChannelRiskOrderContext;
import com.hlkj.pay.dto.order.notify.OrderRiskNotifyDto;
import com.hlkj.pay.gateway.order.IChannelRiskGateway;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author HlpayTeam
 * @date 2025/02/10 14:38
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class ChannelRiskGatewayImpl implements IChannelRiskGateway {

    private final ExtensionExecutor extensionExecutor;

    @Override
    public boolean extensionExist(String channelCode) {
        return extensionExecutor.executeExist(ChannelMerchantRiskExtPt.class, BizScenario.valueOf(channelCode));
    }

    @Override
    public CommonResult<OrderRiskNotifyDto> riskStatusParse(HttpServletRequest request, ChannelRiskOrderContext channelRiskOrderContext) {
        return extensionExecutor.execute(ChannelMerchantRiskExtPt.class,BizScenario.valueOf(channelRiskOrderContext.getOrderComplaintChannelDO().getChannelCode()),
                ex -> ex.riskStatusParse(request, channelRiskOrderContext));
    }

    @Override
    public CommonResult<String> query(ChannelRiskOrderContext channelComplaintOrderContext) {
        return extensionExecutor.execute(ChannelMerchantRiskExtPt.class, BizScenario.valueOf(channelComplaintOrderContext.getOrderComplaintChannelDO().getChannelCode()),
                ex -> ex.queryComplaintNotify(channelComplaintOrderContext));
    }

    @Override
    public CommonResult<String> saveRiskNotifyUrl(ChannelRiskOrderContext channelRiskOrderContext) {
        return extensionExecutor.execute(ChannelMerchantRiskExtPt.class, BizScenario.valueOf(channelRiskOrderContext.getOrderComplaintChannelDO().getChannelCode()),
                ex -> ex.saveRiskNotifyUrl(channelRiskOrderContext));
    }
}
